#ifndef WEBSOCKETPROXY_H
#define WEBSOCKETPROXY_H

#include "websocketserver.h"

class WebSocketProxy : public QObject
{
    Q_OBJECT
public:
    WebSocketProxy(const QString& destination, int destPort, QObject *parent = 0);

    void listen(int port);

public Q_SLOTS:
    void newClient1Connected();
    void newClient2Connected();

    void processClient1Error(QAbstractSocket::SocketError);
    void processClient2Error(QAbstractSocket::SocketError);

    void disconnectClient1();
    void disconnectClient2();

    void dataReceivedFromClient1(QByteArray);
    void dataReceivedFromClient2(QByteArray);

Q_SIGNALS:
    void newTunnel();

private:
    Socket* removeLinkClient1ToClient2(WebSocket* client1);
    WebSocket* removeLinkClient2ToClient1(Socket* client2);


private:
    int v_destinationPort;
    QString v_destinationHostname;

    QMap<WebSocket*,Socket*> v_client1ToClient2;
    QMap<Socket*, WebSocket*> v_client2ToClient1;

    QMap<Socket *, WebSocket*> v_waitingClient;

private:
    WebSocketServer *p_server;
};


#endif // WEBSOCKETPROXY_H
